package org.axed.user.client.axessory;

import org.axed.user.client.AxedArea;
import org.axed.user.client.AxedListener;
import org.axed.user.client.AxedEvent;
import com.google.gwt.user.client.ui.Label;

/**
 * Displays cursor position info, and size. 
 */
public class InfoBar implements AxedListener {
	/**
	 * The label to display the info in.
	 */
	private Label label;

	/**
	 * The axedArea this infobar belongs to.
	 */
	private AxedArea axed;

	/**
	 * Constructor.
	 *
	 * @param label the label to display the info in.
	 */
	public InfoBar(AxedArea axed, Label label) {
		this.axed = axed;
		this.label = label;
	}

	/** 
	 * Handles events generated by axed.
	 * Positions the caret when necessary.
	 */
	public void onAxedEvent(AxedEvent event) {
		switch (event.type) {
		case AxedEvent.INSERT_CHAR :
		case AxedEvent.INSERT_TEXT :
		case AxedEvent.JOIN_LINE : 
		case AxedEvent.MOVE_CURSOR : 
		case AxedEvent.REFRESH : 
		case AxedEvent.REMOVE_CHAR : 
		case AxedEvent.REMOVE_TEXT : 
		case AxedEvent.SPLIT_LINE : 
			label.setText("Line: "  + (axed.getCursorLine() + 1) + 
			              " Col: "  +  axed.getCursorCol() +
						  " Size: " +  axed.size());
			break;
		}
	}
}
